//
//  VerCodeView.m
//  fitnessmanage
//
//  Created by 众拳科技 on 2017/10/17.
//  Copyright © 2017年 zongquankeji. All rights reserved.
//

#import "VerCodeView.h"

@implementation VerCodeView

-(id)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    
    if (self) {
        
        self.backgroundColor = CSWhiteColor;
        
        NSMutableDictionary *attrs = [NSMutableDictionary dictionary];// 创建属性字典
        attrs[NSFontAttributeName] = MidBigFont; // 设置font
        attrs[NSForegroundColorAttributeName] = PlaceHoldColor; // 设置颜色
        
        UIScrollView *scrollView = [[UIScrollView alloc] init];
        [self addSubview:scrollView];
        self.scrollView = scrollView;
        
        /**
         绑定手机号
         */
        UILabel *titleLabel = [[UILabel alloc] init];
        titleLabel.text = @"绑定手机号";
        titleLabel.font = BoldBigFont;
        titleLabel.textColor = CSColorFromRGB(0x0a0a0a);
        [scrollView addSubview:titleLabel];
        self.titleLabel = titleLabel;
        
        /**
         +86
         */
        UILabel *phoneFrontLabel = [[UILabel alloc] init];
        phoneFrontLabel.text = @"+86";
        phoneFrontLabel.font = MidBigFont;
        phoneFrontLabel.textColor = CSColorFromRGB(0x0a0a0a);
        [scrollView addSubview:phoneFrontLabel];
        self.phoneFrontLabel = phoneFrontLabel;
        
        UIImageView *downImageView = [[UIImageView alloc] init];
        downImageView.image = [UIImage imageNamed:@"down"];
        [scrollView addSubview:downImageView];
        self.downImageView = downImageView;
        
        /**
         手机TF
         */
        UITextField *phoneTF = [[UITextField alloc] init];
        //        phoneTF.backgroundColor = CSRedColor;
        phoneTF.clearButtonMode=UITextFieldViewModeWhileEditing;
        phoneTF.keyboardType = UIKeyboardTypeNumberPad;
        phoneTF.font = MidBigFont;
        phoneTF.textColor = CSColorFromRGB(0x212121);
        NSAttributedString *phoneAttStr = [[NSAttributedString alloc] initWithString:@"请输入您的手机号" attributes:attrs]; // 初始化富文本占位字符串
        phoneTF.attributedPlaceholder = phoneAttStr;
        [scrollView addSubview:phoneTF];
        self.phoneTF = phoneTF;
        
        UIView *phoneLineView = [[UIView alloc] init];
        phoneLineView.backgroundColor = LineBackGroundColor;
        [scrollView addSubview:phoneLineView];
        self.phoneLineView = phoneLineView;
        
        /**
         验证码TF
         */
        UITextField *vercodeTF = [[UITextField alloc] init];
        vercodeTF.font = MidBigFont;
        vercodeTF.textColor = CSBlackColor;
        NSAttributedString *vercodeAttStr = [[NSAttributedString alloc] initWithString:@"请输入验证码" attributes:attrs]; // 初始化富文本占位字符串
        vercodeTF.attributedPlaceholder = vercodeAttStr;
        vercodeTF.keyboardType = UIKeyboardTypeNumberPad;
        [scrollView addSubview:vercodeTF];
        self.vercodeTF = vercodeTF;
        
        /**
         发送验证码
         */
        UIButton *sendVercodeBtn = [[UIButton alloc] init];
        [sendVercodeBtn setTitle:@"获取验证码"forState:UIControlStateNormal];
        sendVercodeBtn.titleLabel.font = MidBigFont;
        [sendVercodeBtn setTitleColor:CSColorFromRGB(0x0a0a0a)forState:UIControlStateNormal];
        [sendVercodeBtn setTitleColor:PlaceHoldColor forState:UIControlStateDisabled];
        [scrollView addSubview:sendVercodeBtn];
        self.sendVercodeBtn = sendVercodeBtn;
        
        UIView *phoneineView1 = [[UIView alloc] init];
        phoneineView1.backgroundColor = LineBackGroundColor;
        [scrollView addSubview:phoneineView1];
        self.phoneineView1 = phoneineView1;
        
        /**
         下一步按钮
         */
        UIButton *nextBtn = [[UIButton alloc] init];
        nextBtn.backgroundColor = ButtonBackGroundColor;
        nextBtn.layer.cornerRadius = 4;
        nextBtn.layer.masksToBounds = YES;
        [nextBtn setTitle:@"下一步" forState:UIControlStateNormal];
        [nextBtn setTitleColor:CSBlackColor forState:UIControlStateNormal];
        nextBtn.titleLabel.font = BigFont;
        [scrollView addSubview:nextBtn];
        self.nextBtn = nextBtn;
        
        /**
         密码TF
         */
        UITextField *passWordTF = [[UITextField alloc] init];
        //        passWordTF.backgroundColor = CSRedColor;
        passWordTF.secureTextEntry = YES;
        passWordTF.clearButtonMode=UITextFieldViewModeWhileEditing;
        NSAttributedString *passAttStr = [[NSAttributedString alloc] initWithString:@"请输入密码,至少六位" attributes:attrs]; // 初始化富文本占位字符串
        passWordTF.attributedPlaceholder = passAttStr;
        passWordTF.font = MidBigFont;
        passWordTF.textColor = CSColorFromRGB(0x212121);
        passWordTF.hidden = YES;
        [scrollView addSubview:passWordTF];
        self.passWordTF = passWordTF;
        
        /**
         明文密文显示
         */
        UIButton *lookBtn = [[UIButton alloc] init];
        lookBtn.titleLabel.font = MidFont;
        [lookBtn setImage:[UIImage imageNamed:@"icon_eyes_gary"] forState:UIControlStateNormal];
        [lookBtn setImage:[UIImage imageNamed:@"icon_eyes"] forState:UIControlStateSelected];
        lookBtn.hidden = YES;
        [scrollView addSubview:lookBtn];
        self.lookBtn = lookBtn;
        
        UIView *accountLineView1 = [[UIView alloc] init];
        accountLineView1.hidden = YES;
        accountLineView1.backgroundColor = LineBackGroundColor;
        [scrollView addSubview:accountLineView1];
        self.accountLineView1 = accountLineView1;
        
        [self setConstraints];
    }
    
    return self;
}

-(void)setConstraints{
    
    [self.scrollView mas_remakeConstraints:^(MASConstraintMaker *make) {
    
        make.edges.mas_equalTo(self);
    }];
    
    /**
     绑定手机号
     */
    [self.titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.scrollView).offset(15);
        
        make.left.mas_equalTo(self).offset(25);
        
        make.height.mas_equalTo(60);
    }];
    
    /**
     +86
     */
    [self.phoneFrontLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self).offset(25);
        
        make.centerY.mas_equalTo(self.phoneTF);
        
        make.width.mas_equalTo(35);
    }];
    
    [self.downImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.mas_equalTo(self.phoneFrontLabel);
        
        make.left.mas_equalTo(self.phoneFrontLabel.mas_right);
        
        make.width.height.mas_equalTo(5);
    }];

    
    /**
     手机TF
     */
    [self.phoneTF mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(20);
        
        make.left.mas_equalTo(self.downImageView.mas_right).offset(20);
        
        make.right.mas_equalTo(self).offset(-25);
        
        make.height.mas_equalTo(40);
    }];
    
    [self.phoneLineView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self.phoneFrontLabel);
        
        make.right.mas_equalTo(self).offset(-25);
        
        make.height.mas_equalTo(1);
        
        make.top.mas_equalTo(self.phoneTF.mas_bottom).offset(10);
    }];
    
    /**
     验证码TF
     */
    [self.vercodeTF mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.phoneLineView.mas_bottom).offset(15);
        
        make.left.mas_equalTo(self).offset(25);
        
        make.right.mas_equalTo(self).offset(-25);
        
        make.height.mas_equalTo(self.phoneTF);
    }];
    
    /**
     发送验证码
     */
    [self.sendVercodeBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(self).offset(-15);
        
        make.width.mas_equalTo(120);
        
        make.height.mas_equalTo(30);
        
        make.centerY.mas_equalTo(self.vercodeTF);
    }];
    
    [self.phoneineView1 mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.width.mas_equalTo(self.vercodeTF);
        
        make.height.mas_equalTo(1);
        
        make.top.mas_equalTo(self.vercodeTF.mas_bottom).offset(10);
        
    }];
    
    /**
     密码TF
     */
    [self.passWordTF mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(self.phoneineView1.mas_bottom).offset(15);
        
        make.left.mas_equalTo(self).offset(25);
        
        make.right.mas_equalTo(self).offset(-25);
        
        make.height.mas_equalTo(self.phoneTF);
    }];
    
    /**
     明文密文显示
     */
    [self.lookBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(self).offset(-15);
        
        make.centerY.mas_equalTo(self.passWordTF);
    }];
    
    [self.accountLineView1 mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.width.mas_equalTo(self.passWordTF);
        
        make.height.mas_equalTo(1);
        
        make.top.mas_equalTo(self.passWordTF.mas_bottom).offset(10);
        
    }];
    
    //下一步
    [self.nextBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.accountLineView1.mas_bottom).offset(35);
        
        make.left.mas_equalTo(self).offset(30);
        
        make.right.mas_equalTo(self).offset(-30);
        
        make.height.mas_equalTo(50);
    }];
}


-(void)setFrom:(NSString *)from{
    
    _from = from;
    
    if ([from isEqualToString:@"忘记密码"]) {
        
        self.passWordTF.hidden = NO;
        
        /**
         明文密文显示
         */
        self.lookBtn.hidden = NO;
        
        self.accountLineView1.hidden = NO;
        
        //下一步
        [self.nextBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
            
            make.top.mas_equalTo(self.accountLineView1.mas_bottom).offset(35);
            
            make.left.mas_equalTo(self).offset(30);
            
            make.right.mas_equalTo(self).offset(-30);
            
            make.height.mas_equalTo(50);
        }];
    }
    else{
        
        self.passWordTF.hidden = YES;
        
        /**
         明文密文显示
         */
        self.lookBtn.hidden = YES;
        
        self.accountLineView1.hidden = YES;
        
        //下一步
        [self.nextBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
            
            make.top.mas_equalTo(self.phoneineView1.mas_bottom).offset(35);
            
            make.left.mas_equalTo(self).offset(30);
            
            make.right.mas_equalTo(self).offset(-30);
            
            make.height.mas_equalTo(50);
        }];
    }
    
    [self setNeedsLayout];
    [self layoutIfNeeded];
    
    self.scrollView.contentSize = CGSizeMake(self.frame.size.width, CGRectGetMaxY(self.nextBtn.frame)  + 10 + CZQ_NavigationBarHeight + CZQ_StatusBarHeight);
    
    
}
@end
